package com.ruix.app.network.request;

import com.ruix.app.network.RequestParams;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import okhttp3.FormBody;
import okhttp3.RequestBody;

/**
 * Created by hadexs on 2017/4/12.
 */

public class RXPostFormRequst extends RXRequest{


    public RXPostFormRequst() {
    }

    public RXPostFormRequst(RequestParams paramaters) {
        this.parama = paramaters;
    }



    public RequestBody buildRequestBody() {
        if (parama != null && parama.getPostFormParams() != null) {
            FormBody.Builder builder = new FormBody.Builder();

            JSONObject formParms = parama.getPostFormParams();
            Iterator<String> keys =  formParms.keys();
            if (keys != null) {
                while (keys.hasNext()) {
                    String key = keys.next();
                    builder.add(key,formParms.optString(key));
                }
            }
            FormBody formBody = builder.build();
            return formBody;
        } else {
            return null;
        }
    }

//    @Override
//    public void buildRequestLog() {
//        addRequestLog("url", getUrl());
//        addRequestLog("tag", getTag());
//        addRequestLog(null, "---------requestBody---------");
//        if (getParamaters() != null) {
//            addRequestLog(null, getParamaters().toString());
//        }
//
//        // TODO Ray
//        getHwfRequestLog().setReqUrl(getUrl())// 设置请求接口地址
//                .setReqMethod(getTag())// 设置请求方法
//                .setReqMsgPostParams(JsonUtil.map2Json(getParamaters()));// 设置请求报文
//    }


}
